package com.trex.modules.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JsonToMapParserDetil {
    public static void parseJsonToTable(String jsonString) throws JsonProcessingException {
        // 创建 ObjectMapper 对象
        ObjectMapper objectMapper = new ObjectMapper();


        JsonNode rootNode = objectMapper.readTree(jsonString);

        // 解析 BODY 并放入 Map 中
        JsonNode bodyNode = rootNode.path("Tables").path("BODY").get(0); // 假设 BODY 只有一个对象
        Map<String, String> bodyMap = new HashMap<>();
        bodyMap.put("OPERATION_FLAG", bodyNode.path("OPERATION_FLAG").asText());
        bodyMap.put("FLAG", bodyNode.path("FLAG").asText());
        bodyMap.put("STATUS", bodyNode.path("STATUS").asText());
        bodyMap.put("STATION_USER_CODE", bodyNode.path("STATION_USER_CODE").asText());
        bodyMap.put("STATION_USER_NAME", bodyNode.path("STATION_USER_NAME").asText());
        bodyMap.put("STATION_TIME", bodyNode.path("STATION_TIME").asText());

        JsonNode detailArray = rootNode.path("Tables").path("DETAIL");
        List<Map<String, String>> detailList = new ArrayList<>();
        for (JsonNode detailNode : detailArray) {
            Map<String, String> detailMap = new HashMap<>();
            detailMap.put("REC_ID", detailNode.path("REC_ID").asText());
            detailMap.put("WAGONNO", detailNode.path("WAGONNO").asText());
            detailList.add(detailMap);
        }
        String FLAG = bodyMap.get("OPERATION_FLAG").toString();

        if (FLAG == "1"){
            for (Map<String, String> stringStringMap : detailList) {
//                tblXdJxchsdDao.updateInfo(stringStringMap.get("REC_ID"),bodyMap.get("STATUS"),bodyMap.get("STATION_USER_CODE"),bodyMap.get("STATION_USER_NAME"),bodyMap.get("STATION_TIME"));
            }


        }else if (FLAG == "2"){

            for (Map<String, String> stringStringMap : detailList) {
//                tblXdZxxdctzdDao.updateInfo(stringStringMap.get("REC_ID"),bodyMap.get("STATUS"),bodyMap.get("STATION_USER_CODE"),bodyMap.get("STATION_USER_NAME"),bodyMap.get("STATION_TIME"));
            }
        }

    }
    public static void main(String[] args) throws JsonProcessingException {
        String json = "";

       parseJsonToTable(json);


    }
}
